<?php defined('IN_PHPCMS') or exit('Access Denied'); ?>//随屏移动广告模板  2008-10-09 李勇
<?php 
if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')){
$css_position='absolute';
}else{
$css_position='fixed';
}
$place=$adses[0];
$placeheight=$place['height']+16;
?>

//生成一个浮动层,自动裁剪
document.write('<div id="FloatDiv<?php echo $placeid;?>" style="width: <?php echo $place['width'];?>px;height: <?php echo $placeheight;?>px;float: left;top: 0px;left: 0px;position: <?php echo $css_position;?>;z-index: 100;display:none; overflow:hidden; ">');

//收缩,展开按钮的动作
function swapDiv<?php echo $placeid;?>(btn){
obj=document.getElementById('FloatDiv<?php echo $placeid;?>');
if(btn.value=='关闭'){
btn.value='展开';
obj.style.height='16px';
}else{
btn.value='关闭';
obj.style.height=16+<?php echo $place['height'];?>+'px';
}
FloatEvent<?php echo $placeid;?>();
}

//收缩,展开按钮
document.write('<?php echo $place['placename'];?><input type="button" value="关闭" onclick="swapDiv<?php echo $placeid;?>(this)" /><br/>');

//循环此广告位每一个广告(但只显示一个)
<?php if(is_array($contents)) foreach($contents AS $i => $content) { ?>
<?php $ads=$adses[$i];?>

//广告内容,可以是图片,影片,SWF等
<?php if($ads['type']=='image') { ?>
<?php echo $content['0'];?>
<?php } else { ?>
<?php echo $content;?>
<?php } ?>
<?php } ?>	

//广告位层的结束
document.write('</div>');

//根据位置,生成事件代码
<?php  
$position=$place['position'];
$floatDivInterval="obj=document.getElementById('FloatDiv$placeid');de=document.documentElement;";
$xpos=substr($position,0,1);
$ypos=substr($position,1,1);

if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')){
$deTop='de.scrollTop';
$deLeft='de.scrollLeft';
$deHeight='de.offsetHeight';
$deWidth='de.offsetWidth';
$objHeight='obj.style.posHeight';
$objWidth='obj.style.posWidth';
}else{
$deTop='0';
$deLeft='0';
$deHeight='de.clientHeight';
$deWidth='de.clientWidth';
$objHeight='parseInt(obj.style.height)';
$objWidth='parseInt(obj.style.width)';
}			

//Y方向调整
if($ypos=='t')
$floatDivInterval.="obj.style.top=$deTop+'px';";
elseif($ypos=='m')
$floatDivInterval.="obj.style.top=($deTop+($deHeight-$objHeight-16)/2)+'px';";	
elseif($ypos=='b') 
$floatDivInterval.="obj.style.top=($deTop+$deHeight-$objHeight-16)+'px';";

//X方向调整
if($xpos=='l')
$floatDivInterval.="obj.style.left=$deLeft+'px';";
elseif($xpos=='m')
$floatDivInterval.="obj.style.left=($deLeft+($deWidth-$objWidth-16)/2)+'px';";
elseif($xpos=='r')
$floatDivInterval.="obj.style.left=($deLeft+$deWidth-$objWidth-16)+'px';";

//显示此层(因为最初是隐藏的)
$floatDivInterval.="obj.style.display='block';";
?>	



//将事件代码挂到滚动与大小调整事件上
function FloatEvent<?php echo $placeid;?>(){
<?php echo $floatDivInterval;?>
}

$(function(){
de=document.documentElement;	

//IE响应此事件
old=de.onscroll;
func=FloatEvent<?php echo $placeid;?>;
if(typeof de.onscroll !='function'){
de.onscroll=func;
}else{
de.onscroll=function(){
old();
func();
}
}
  
//IE响应
old=de.onresizeend;
if(typeof de.onresizeend !='function'){
de.onresizeend=func;
}else{
de.onresizeend=function(){
old();
func();
}
}

//FF响应
old=window.onresize;
if(typeof window.onresize !='function'){
window.onresize=func;
}else{
window.onresize=function(){
old();
func();
}
}

  	func();
});
